<template>
  <div class="app-registry__step-four">
    <div class="app-registry__step-four__content">
      <input type="text" placeholder="请确认密码" v-model="rpassword">
      <button :disabled="disable" @click="CheckPassword">注册</button>
    </div>
  </div>
</template>
<script>
import { postRegistryApi } from '@/api/haigou'

import Vue from 'vue'
import { Dialog, Toast } from 'vant'

Vue.use(Toast)
export default {
  name: 'AppRegistryStepFour',
  props: ['tel', 'password'],
  data () {
    return {
      rpassword: ''
    }
  },
  computed: {
    disable () {
      // return !/^[1-9a-zA-Z]\w{5,11}$/.test(this.rpassword)
      return !(this.rpassword === this.password)
    }
  },
  methods: {
    async CheckPassword () {
      try {
        await postRegistryApi(this.tel, this.password)
        Dialog.confirm({
          message: '注册成功，是否跳转到登录?',
          cancelButtonText: '回到首页'
        }).then(() => {
          this.$router.replace({ name: 'login' })
        }).catch(() => {
          this.$router.replace({ name: 'home' })
        })
      } catch (error) {
        console.log(error.message)
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.app-registry__step-four {
  &__content {
    padding: 0.16rem .35rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    input {
      width: 100%;
      height: 50px;
      margin: 20px 0;
      border: none;
      background: rgb(240, 240, 240);
      border-radius: 15px;
      padding: 0 20px;
      margin-top: 0;
    }
    button {
      width: 100%;
      height: 50px;
      border-radius: .4rem;
      border: none;
      background: rgb(84, 167, 250);
      font-size: 18px;
      color: white;
    }
    button:disabled {
      background: rgb(181, 218, 255);
    }
  }
}
</style>
